home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
PGM_TOOL
/
PARAMS
/
SKEL.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-02-02
|
4KB
|
166 lines
program Skel;
{%
This is a "skeleton" application; copy this file
and edit to add application-dependant operations.
Five sections follow:
global declarations
procedure ShowUsage
procedure SetOpt
procedure DoFile
main body
}
{----------------------------------------------------------}
uses Dos, Params; {% others?}
const
{% Identify program name, version, date, and/or copyright:}
{Update with each revision!}
CopyNote = 'SKEL prototype 11-3-93';
{configuration data; compatable with CONFIG program:}
type
tConfig = record
Magic: string[10];
Data: string[255]; {% max length = 255}
end;
const
Config: tConfig = (
Magic: '!)@(#*$&%^'; {must appear nowhere else in code!}
{% overwrite default options here: (51 char's per line) }
Data: '///////////////////////////////////////////////////'+
'///////////////////////////////////////////////////'+
'///////////////////////////////////////////////////'+
'///////////////////////////////////////////////////'+
'///////////////////////////////////////////////////'
{'/' padding reserves space for reconfiguration}
);
{----------------------------------------------------------}
{ShowUsage: explain command-line parameters and options:}
procedure ShowUsage; far;
begin
writeln(CopyNote);
writeln('Usage:');
{% explain parameters & options here}
writeln('Default options are: ', GetDefaults(Config.data));
end; {ShowUsage}
{----------------------------------------------------------}
{SetOpt: set the option named OptChr to the value given by OptStr:}
{ Uses GetBool for booleans; e.g., /a+ /b /c- : a,b true, c false }
{ Uses GetInt for integers; e.g., /a-16 /b23 : sets a= -16, b= 23 }
{ String values are direct; e.g., /fSomeName : sets f= 'SomeName' }
procedure SetOpt; far;
begin
{Optn:= ExtendOpt;} {% to use 2-char Optn instead of OptChr}
case OptChr of
{% process option here}
{% use "if ParNo < 0" for initial-only options}
'?': begin
PAppDone;
ShowUsage;
Halt;
end;
{none of the above:}
else RptError('Undefined option', Option, 'u');
end;
end; {SetOpt}
(***** an alternative, for 2-character option names: *****
procedure SetOpt; far;
var
Optn: ExtStr;
begin
Optn:= ExtendOpt; {try to extend option name to 2 chars}
{use "if .. else if .." instead of "case of .."}
if Optn = 'ab' then begin
{% process option here}
{% use "if ParNo < 0" for initial-only options}
end else if Optn = '?' then begin
PAppDone;
ShowUsage;
Halt;
end else begin {none of the above:}
RptError('Undefined option', Option, 'u');
end;
end; {SetOpt}
***********************************************************)
{----------------------------------------------------------}
{DoFile: process the file (or name) FName:}
{%
If Expdd = true, FName is expanded name of file found in Dir,
and global variables Path, Dir, and SRec may be used;
else, FName is just the ParStr, and not necessarily a filename.
Use "IsFile" to count FName as a file.
}
procedure DoFile(FName: PathStr; Expdd: boolean); far;
procedure IsFile;
begin
if not Expdd then begin
inc(FileNo); inc(FPars);
end;
end;
begin {DoFile}
{% process file here according to options}
end; {DoFile}
{AppDone: prepare to exit from the application:}
procedure AppDone; far;
begin
{% do anything needed for an orderly exit}
{.. but don't halt}
end; {AppDone}
{----------------------------------------------------------}
begin {main program}
{mandatory: initialize procedure variables:}
PShowUsage:= ShowUsage;
PSetOpt:= SetOpt;
PDoFile:= DoFile;
PAppDone:= AppDone;
{ParNo is < 0 here}
ParseOpts(Config.Data); {set default options}
if ParamCount = 0 then begin {% optional}
ShowUsage;
halt;
end;
{% MayExpand:= false; -- if desired to override default}
{ParNo := 1 to ParamCount used here:}
ScanPars; {scan the command line}
{% process here according to options}
AppDone;
end.